package com.aree.caipiao.shsq.util;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.aree.caipiao.shsq.model.ShuangSeQiuNumbers;

public final class ShuangSeQiuUtil {
	private static Log log = LogFactory.getLog(ShuangSeQiuUtil.class);
	private ShuangSeQiuUtil() {};
	private static List<ShuangSeQiuNumbers> allNumbersCache = null;
	private static List<Integer> allNumbersIndexesCache = null;
	
	public static int TOTAL = 17721088;
	
	/**
	 * 生成双色球所有的全部的组合
	 * @return
	 */
	public static List<ShuangSeQiuNumbers> generateAllNumbers() {
		if (allNumbersCache != null) return allNumbersCache;
		log.debug("正在生成全部的号码组合...");
		List<ShuangSeQiuNumbers> all = new ArrayList<ShuangSeQiuNumbers>(TOTAL);
		for (int red1=1; red1 <=28; red1++) {
			for (int red2=red1+1; red2<=29; red2++) {
				for (int red3=red2+1; red3<=30; red3++) {
					for (int red4=red3+1; red4<=31; red4++) {
						for (int red5=red4+1; red5<=32; red5++) {
							for (int red6=red5+1; red6<=33; red6++) {
								for (int blue=1; blue<=16; blue++) {
									//log.debug("正在生成号码[" + red1 + "," + red2 + "," + red3 + "," + red4 + "," + red5 + "," + red6 + "," + blue + "]");
									all.add(new ShuangSeQiuNumbers(red1, red2, red3, red4, red5, red6, blue));
								}
							}
						}
					}
				}
			}
		}
		allNumbersCache = all;
		log.debug("全部的号码组合生成完毕");
		return allNumbersCache;
	}
	
	/**
	 * 生成双色球全部组合的索引列表
	 * @return
	 */
	public static List<Integer> generateAllNumbersIndexes() {
		if (allNumbersIndexesCache != null) return allNumbersIndexesCache;
		log.debug("正在生成全部的号码索引组合...");
		List<Integer> all = new ArrayList<Integer>(TOTAL);
		for (int index=0; index < 17721088; index++) {
			all.add(index);
		}
		allNumbersIndexesCache = all;
		log.debug("全部的号码组合索引生成完毕");
		return allNumbersIndexesCache;
	}
	
	/**
	 * 保证号码以两位显示
	 * @param number
	 * @return
	 */
	public static String len2(int number) {
		String result = String.valueOf(number);
		if (result.length() < 2) result = "0" + result;
		return result;
	}
}
